home *** CD-ROM | disk | FTP | other *** search
- Path: dawn.mmm.com!news
- From: kjhopps@mmm.com (Kevin J Hopps)
- Newsgroups: comp.lang.c++
- Subject: Re: GOTO and C++.
- Date: 12 Mar 1996 15:08:36 GMT
- Organization: 3M - St. Paul, MN 55144-1000 US
- Message-ID: <4i441k$8nu@dawn.mmm.com>
- References: <4i2bm7$bmu@masala.cc.uh.edu>
- Reply-To: kjhopps@mmm.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- sukumar (sukku@menudo.uh.edu) wrote:
- > Hi,
- > Are there any inherent problems with GOTO and C++. In my application,
- > I using GOTO and it crashes. If I remove the goto and replace it with a flag,
- > everyting works fine. This is how the code looks:
-
- > f()
- > {
-
- > char** n = NULL;
-
- > n = new char*[20];
- > for(i=0; i<20; i++)
- > n[i] = new char[10];
-
- > ...trivial error checking
-
- > if(error)
- > goto CLEANUP;
-
-
- > ...
- > I use come RWCStrings (String class) here
- > ...
-
- > CLEANUP:
- > for(i=0; i<20; i++)
- > delete [] n[i];
-
- > delete [] n;
- > }
-
- > The program crashes on delete [] n. If I remove the goto and replace it with
- > the code at the CLEANUP, I am fine. I was testing the case where error is True.
- > The debugger says there is a problem in the RWCString class.
-
- > I could only conclude that goto is causing the initialization of some vars to
- > screw up.
-
- > I'd appreciate it if someone can throw some light on this.
-
- If you skip over the instantiations of the RWCStrings, they will not be
- initialized and will contain garbage. However, when they go out of scope,
- their destructors will be called. Probably this is corrupting the heap,
- so that the deletes after CLEANUP don't work properly.
- --
- Kevin J. Hopps, 3M Company kjhopps@mmm.com
- Opinions are my own. I don't speak for 3M.
- But 3M speaks for me -- I did not write the following line:
-
- Opinions expressed herein are my own and may not represent those of 3M.
-